/*
 * AppendingTextPane.java
 *
 * Created on February 21, 2008, 7:55 PM
 */


import javax.swing.JTextPane;

import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.StyledDocument;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTML.Tag;
import javax.swing.text.html.HTMLEditorKit;
import java.io.IOException;
/**
 *
 * @author  Brian
 */
public class AppendingTextPane extends JTextPane {
  public AppendingTextPane() {
    super();

        setContentType("text/html");
  }

  public AppendingTextPane(StyledDocument doc) {
    super(doc);

        setContentType("text/html");
  }

  // Appends text to the document and ensure that it is visible
  public void append(String text) {
        try{
            HTMLDocument doc = (HTMLDocument)this.getDocument();
            HTMLEditorKit editorKit = (HTMLEditorKit)this.getEditorKit();
            editorKit.insertHTML(doc, doc.getLength(), text, 0, 0, null);
            this.select(doc.getLength(), doc.getLength());
        } catch (IOException e){
        } catch (BadLocationException e) {
        }
        
  }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
    
}
